<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客户管理</title>
  <link href="../../css/style.css" rel="stylesheet" type="text/css" />
  <!--axios-->
  <script type="text/javascript" src="../../js/axios.js"></script>
  <script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
  <script type="text/javascript" src="../../js/api.js"></script>
  <link rel="stylesheet" href="../../layui/css/layui.css">
  <script type="text/javascript" src="../../layui/layui.js"></script>
  <script>
    layui.use('laydate', function() {
      var laydate = layui.laydate;
      laydate.render({
        elem: '#startTime'
        ,type: 'datetime'
      });
      laydate.render({
        elem: '#endTime'
        ,type: 'datetime'
      });
    })
    function formatNumber(number, decimals, dec_point, thousands_sep) {
      /*
      * 参数说明：
      * number：要格式化的数字
      * decimals：保留几位小数
      * dec_point：小数点符号
      * thousands_sep：千分位符号
      * */
      number = (number + '').replace(/[^0-9+-Ee.]/g, '');
      var n = !isFinite(+number) ? 0 : +number,

              prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
              sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
              dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
              s = '',
              toFixedFix = function (n, prec) {
                var k = Math.pow(10, prec);
                return '' + Math.floor(n * k) / k;
              };
      s = (prec ? toFixedFix(n, prec) : '' + Math.floor(n)).split('.');
      var re = /(-?\d+)(\d{3})/;
      while (re.test(s[0])) {
        s[0] = s[0].replace(re, "$1" + sep + "$2");
      }

      if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
      }
      $("#Money").val(s.join(dec))
    }
    $(function (){
      load(1,5);
      $("#suborders").click(function (){
        window.event.returnValue=false;
        orderId= $("#orderId").val()
        customName= $("#customName").val()
        startTime= $("#startTime").val()
        endTime= $("#endTime").val()
        minMoney= $("#minMoney").val()
        maxMoney= $("#maxMoney").val()
        load(1,5,orderId,customName,startTime,endTime,minMoney,maxMoney);
        if (minMoney!=null&&maxMoney!=null){
          if (minMoney>maxMoney){
            layui.use('layer', function(){
              var layer = layui.layer;
              layer.msg("你很调皮，但是霸霸宠你！",{icon:1})
            });
          }
        }
        if(startTime!=null&&endTime!=null){
          if (startTime>endTime){
            layui.use('layer', function(){
              var layer = layui.layer;
              layer.msg("你很调皮，但是霸霸宠你！",{icon:1})
            });
          }
        }
        layui.use('layer', function(){
          var layer = layui.layer;
          layer.msg("查询成功！",{icon:1})
        });
      })
    })
    function load(currentpage,rows,orderId,customName,startTime,endTime,minMoney,maxMoney){
      let statu="1"
      var url="http://121.37.227.40:8000/"
      axios({
        url:url+'marketing/marketingOrdersPage',
        method:"POST",
        data:{
        },
        params:{
          currentPage: currentpage,
          rows: rows,
          orderId:orderId,
          customName:customName,
          startTime:startTime,
          endTime:endTime,
          minMoney:minMoney,
          maxMoney:maxMoney,
          status:statu
        },
        dataType:"JSON"
      }).then(function (rel) {
        rel = rel.data;
        let str='<thead>\n' +
                '        <tr>\n' +
                '          <th>序号</th>\n' +
                '          <th>订单编号</th>\n' +
                '          <th>客户姓名</th>\n' +
                '          <th>联系电话</th>\n' +
                '          <th>订购时间</th>\n' +
                '          <th>金额</th>\n' +
                '          <th>操作人</th>\n' +
                '          <th>审核状态</th>\n' +
                '          <th>操作</th>\n' +
                '        </tr>\n' +
                '      </thead>'
        str+='<tbody>'
        let li;
        for (var i=0;i<rel.resultData.list.length;i++) {
          let data = rel.resultData.list[i];
          formatNumber(parseFloat(data.orderMoney), 2, ".", ",")
          var money = $("#Money").val()
          let status = data.status;
          if (status==1){
            status = "审核中";
            li+='<tr>\n' +
                    '          <td>' + ((i + 1) +((currentpage-1)*rows))+ '</td>\n' +
                    '          <td>'+data.orderId +'</td>\n' +
                    '          <td>'+data.customName.customName +'</td>\n' +
                    '          <td>'+data.customName.telephone+'</td>\n' +
                    '          <td>'+data.orderTime+'</td>\n' +
                    '          <td>￥'+money+'</td>\n' +
                    '          <td>'+data.operator.uName +'</td>\n' +
                    '          <td>'+status+'</td>\n' +
                    '          <td>\n' +
                    '            <a href="javascript:void(0)" class="tablelink" onclick="goExmine(\''+data.orderId +'\')">审核</a>\n' +
                    '          </td>\n' +
                    '        </tr>'
          }
        }
        str+=li
        str+='</tbody>';
        $(".tablelist").html(str);
        $('.tablelist tbody tr:odd').addClass('odd');

        layui.use("laypage",function (){
          var laypage=layui.laypage;
          laypage.render({
            elem:"page",
            count:rel.resultData.totalCount,
            theme: '#eb5409',
            limit:rows,
            limits:[3,5,10],
            curr:currentpage,
            layout:['prev','page','next','limit','count','skip'],
            jump:function (obj,first){
              currentpage=obj.curr
              rows=obj.limit
              if (!first){
                load(currentpage,rows,orderId,customName,startTime,endTime,minMoney,maxMoney)
              }
            }
          })
        })
      })
    }
    function goExmine(orderId) {
      location.href="orderExamine.html?orderId="+orderId
    }
  </script>
</head>
<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>营销管理</li>
    <li>订购单审核管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post">
    <ul class="tools">
      <li> 订单编号:
        <input type="text" id="orderId" />
      </li>
      <li> 客户姓名:
        <input type="text" id="customName"/>
      </li>
      <li> 订购时间:
        <input type="text" id="startTime"/>-<input type="text" id="endTime"/>
      </li>
      <li> 金额:
        <input type="text" class="stinput" id="minMoney"/>-<input type="text" class="stinput" id="maxMoney" />
      </li>
      <li class="subBut"  id="suborders"><img src="../../images/t06.png" />查询</li>
    </ul>
    <table class="tablelist">
<!--      <thead>-->
<!--        <tr>-->
<!--          <th>序号</th>-->
<!--          <th>订单编号</th>-->
<!--          <th>客户姓名</th>-->
<!--          <th>联系电话</th>-->
<!--          <th>订购时间</th>-->
<!--          <th>金额</th>-->
<!--          <th>操作人</th>-->
<!--          <th>审核状态</th>-->
<!--          <th>操作</th>-->
<!--        </tr>-->
<!--      </thead>-->
<!--      <tbody>-->
<!--        <tr>-->
<!--          <td>1</td>-->
<!--          <td>DJ201701270001</td>-->
<!--          <td>王金平</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>2017-01-25 15:05:05</td>-->
<!--          <td>￥9,876,582</td>-->
<!--          <td>关羽</td>-->
<!--          <td>审核中</td>-->
<!--          <td>-->
<!--            <a href="orderExamine.html" class="tablelink">审核</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td>2</td>-->
<!--          <td>DJ201701270002</td>-->
<!--          <td>张永祥</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>2017-01-25 15:05:05</td>-->
<!--          <td>￥9,876,582</td>-->
<!--          <td>关羽</td>-->
<!--          <td>审核中</td>-->
<!--          <td>-->
<!--            <a href="orderExamine.html" class="tablelink">审核</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--      </tbody>-->
    </table>
    <div class="pagin" id="page">
<!--      <div class="message">共<i class="blue">1256</i>条记录，当前显示第&nbsp;<i class="blue">2&nbsp;</i>页</div>-->
<!--      <ul class="paginList">-->
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">1</a></li>-->
<!--        <li class="paginItem current"><a href="javascript:;">2</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">3</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">4</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">5</a></li>-->
<!--        <li class="paginItem more"><a href="javascript:;">...</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">10</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
<!--      </ul>-->
    </div>
  </form>
</div>
<div><input id="Money" style="display: none"></div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
